package com.csii.adhoc.controller.info;

import com.csii.adhoc.annotation.OperationLog;
import com.csii.adhoc.info.depart.DepartPo;
import com.csii.adhoc.info.depart.DepartVo;
import com.csii.adhoc.info.depart.service.DepartService;
import com.csii.adhoc.util.DateUtils;
import com.csii.result.APIResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * @description: 部门控制层
 * @author: panChuanJiang
 * @create: 2021-01-26 11:29
 */
@RestController
@Slf4j
@RequestMapping("/department")
public class DepartController {
    @Resource
    private DepartService departService;

    @RequestMapping("departmentMaintain")
    @OperationLog("部门维护")
    public APIResult departmentMaintain(@RequestBody DepartVo departVo) {
        String userId = Optional.ofNullable(String.valueOf(SecurityUtils.getSubject().getPrincipal())).orElse("未知用户");
        departVo.setUpdatedBy(userId)
                .setUpdatedDt(DateUtils.getDateString("yyyyMMddHHmmss"));
        departService.departMaintain(departVo, departVo.getOptMode());
        return APIResult.successResult(null);
    }

    @RequestMapping("departmentQuery")
    public APIResult departmentQuery(@RequestBody(required = false) DepartPo departPo) {
        return APIResult.successResult(departService.selectListDepart(departPo));
    }
}
